![]() |
![]() |
![]() | |
![]() ![]() ![]() ![]()
╨Φ±εΓαφΦσ Γ εΩφσ |
╨Φ±εΓαφΦσ πσε∞σ≥≡Φ≈σ±ΩΦ⌡ ⌠Φπ≤≡┬ ²≥ε∞ ≡ατΣσδσ ∞√ ε∩Φ°σ∞ ∞σ≥εΣ√ Ωδα±±α Graphics, ∩≡σΣφατφα≈σφφ√σ Σδ ≡Φ±εΓαφΦ ²δσ∞σφ≥α≡φ√⌡ πσε∞σ≥≡Φ≈σ±ΩΦ⌡ ⌠Φπ≤≡, ≥αΩΦ⌡ ΩαΩ δΦφΦΦ, ∩≡ ∞ε≤πεδⁿφΦΩΦ, εΩ≡≤µφε±≥Φ Φ ≥αΩ Σαδσσ. ╦ΦφΦΦ─δ ≥επε ≈≥εß√ φα≡Φ±εΓα≥ⁿ ∩≡ ∞≤■ ≥εφΩ≤■ ±∩δε°φ≤■ δΦφΦ■, Γ√ ∞εµσ≥σ Γε±∩εδⁿτεΓα≥ⁿ± ∞σ≥εΣε∞ drawLine, ∩≡ε≥ε≥Φ∩ Ωε≥ε≡επε ∩≡ΦΓσΣσφ φΦµσ: public abstract void drawLine(int x1, int y1,int x2, int y2); ╩εφ÷√ δΦφΦΦ Φ∞σ■≥ Ωεε≡ΣΦφα≥√ (x1, y1) Φ (x2, y2), ΩαΩ ²≥ε ∩εΩαταφε φα ≡Φ±. 1. ╨Φ±. 1. ╨Φ±εΓαφΦσ ∩≡ ∞εΘ δΦφΦΦ ╩ ±εµαδσφΦ■, Γ Ωεφ≥σΩ±≥σ ε≥εß≡αµσφΦ φσ ∩≡σΣ≤±∞ε≥≡σφ√ φΦΩαΩΦσ α≥≡Φß≤≥√, ∩ετΓεδ ■∙Φσ φα≡Φ±εΓα≥ⁿ ∩≤φΩ≥Φ≡φ≤■ δΦφΦ■ ΦδΦ δΦφΦ■ ≤ΓσδΦ≈σφφεΘ ≥εδ∙Φφ√. ╧≡ ∞ε≤πεδⁿφΦΩΦ Φ ΩΓαΣ≡α≥√╤≡σΣΦ ∞σ≥εΣεΓ Ωδα±±α Graphics σ±≥ⁿ φσ±ΩεδⁿΩε, ∩≡σΣφατφα≈σφφ√⌡ Σδ ≡Φ±εΓαφΦ ∩≡ ∞ε≤πεδⁿφΦΩεΓ. ╧σ≡Γ√Θ Φτ φΦ⌡, ± Φ∞σφσ∞ drawRect, ∩ετΓεδ σ≥ φα≡Φ±εΓα≥ⁿ ∩≡ ∞ε≤πεδⁿφΦΩ, ταΣαφφ√Θ Ωεε≡ΣΦφα≥α∞Φ ±Γεσπε δσΓεπε Γσ≡⌡φσπε ≤πδα, °Φ≡ΦφεΘ Φ Γ√±ε≥εΘ: public void drawRect(int x, int y, int width, int height); ╧α≡α∞σ≥≡√ x Φ y ταΣα■≥, ±εε≥Γσ≥±≥Γσφφε, Ωεε≡ΣΦφα≥√ Γσ≡⌡φσπε δσΓεπε ≤πδα, α ∩α≡α∞σ≥≡√ width Φ height - Γ√±ε≥≤ Φ °Φ≡Φφ≤ ∩≡ ∞ε≤πεδⁿφΦΩα (≡Φ±. 2). ╨Φ±. 2. ╨Φ±εΓαφΦσ ∩≡ ∞ε≤πεδⁿφΦΩα ┬ ε≥δΦ≈Φσ ε≥ ∞σ≥εΣα drawRect, ≡Φ±≤■∙σπε ≥εδⁿΩε ∩≡ ∞ε≤πεδⁿφ≤■ ≡α∞Ω≤, ∞σ≥εΣ fillRect ≡Φ±≤σ≥ τα∩εδφσφφ√Θ ∩≡ ∞ε≤πεδⁿφΦΩ. ─δ ≡Φ±εΓαφΦ Φ τα∩εδφσφΦ ∩≡ ∞ε≤πεδⁿφΦΩα Φ±∩εδⁿτ≤σ≥± ÷Γσ≥, Γ√ß≡αφφ√Θ Γ Ωεφ≥σΩ±≥ ε≥εß≡αµσφΦ (≡Φ±. 3). ╨Φ±. 3. ╨Φ±εΓαφΦσ τα∩εδφσφφεπε ∩≡ ∞ε≤πεδⁿφΦΩα ╧≡ε≥ε≥Φ∩ ∞σ≥εΣα fillRect ∩≡ΦΓσΣσφ φΦµσ: public abstract void fillRect(int x, int y, int width, int height); ╠σ≥εΣ drawRoundRect ∩ετΓεδ σ≥ φα≡Φ±εΓα≥ⁿ ∩≡ ∞ε≤πεδⁿφΦΩ ± ταΩ≡≤πδσφφ√∞Φ ≤πδα∞Φ: public abstract void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight); ╧α≡α∞σ≥≡√ x Φ y ε∩≡σΣσδ ■≥ Ωεε≡ΣΦφα≥√ Γσ≡⌡φσπε δσΓεπε ≤πδα ∩≡ ∞ε≤πεδⁿφΦΩα, ∩α≡α∞σ≥≡√ width Φ height ταΣα■≥, ±εε≥Γσ≥±≥Γσφφε σπε °Φ≡Φφ≤ Φ Γ√±ε≥≤. ╨ατ∞σ≡√ ²δδΦ∩±α, εß≡ατ≤■∙σπε ταΩ≡≤πδσφΦ ∩ε ≤πδα∞, Γ√ ∞εµσ≥σ ταΣα≥ⁿ ± ∩ε∞ε∙ⁿ■ ∩α≡α∞σ≥≡εΓ arcWidth Φ arcHeight. ╧σ≡Γ√Θ Φτ φΦ⌡ ταΣασ≥ °Φ≡Φφ≤ ²δδΦ∩±α, α Γ≥ε≡εΘ - Γ√±ε≥≤ (≡Φ±. 4).
╨Φ±. 4. ╨Φ±εΓαφΦσ ∩≡ ∞ε≤πεδⁿφΦΩα ± ταΩ≡≤πδσφφ√∞Φ ≤πδα∞Φ ╠σ≥εΣ fillRoundRect ∩ετΓεδ σ≥ φα≡Φ±εΓα≥ⁿ τα∩εδφσφφ√Θ ∩≡ ∞ε≤πεδⁿφΦΩ ± ταΩ≡≤πδσφφ√∞Φ ≤πδα∞Φ (≡Φ±. 5). ╨Φ±. 5. ╨Φ±εΓαφΦσ τα∩εδφσφφεπε ∩≡ ∞ε≤πεδⁿφΦΩα ± ταΩ≡≤πδσφφ√∞Φ ≤πδα∞Φ ═ατφα≈σφΦσ ∩α≡α∞σ≥≡εΓ ²≥επε ∞σ≥εΣα αφαδεπΦ≈φε φατφα≈σφΦ■ ∩α≡α∞σ≥≡εΓ ≥εδⁿΩε ≈≥ε ≡α±±∞ε≥≡σφφεπε ∞σ≥εΣα drawRoundRect: public abstract void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight); ╠σ≥εΣ fill3Drect ∩≡σΣφατφα≈σφ Σδ ≡Φ±εΓαφΦ Γ√±≥≤∩α■∙σπε ΦδΦ τα∩αΣα■∙σπε ∩≡ ∞ε≤πεδⁿφΦΩα: public void fill3DRect(int x, int y, int width, int height, boolean raised); ┼±δΦ τφα≈σφΦσ ∩α≡α∞σ≥≡α raised ≡αΓφε true, ≡Φ±≤σ≥± Γ√±≥≤∩α■∙ΦΘ ∩≡ ∞ε≤πεδⁿφΦΩ, σ±δΦ false - τα∩αΣα■∙ΦΘ. ═ατφα≈σφΦσ ε±≥αδⁿφ√⌡ ∩α≡α∞σ≥≡εΓ αφαδεπΦ≈φε φατφα≈σφΦ■ ∩α≡α∞σ≥≡εΓ ∞σ≥εΣα drawRect. ╠φεπε≤πεδⁿφΦΩΦ─δ ≡Φ±εΓαφΦ ∞φεπε≤πεδⁿφΦΩεΓ Γ Ωδα±±σ Graphics ∩≡σΣ≤±∞ε≥≡σφε ≈σ≥√≡σ ∞σ≥εΣα, ΣΓα Φτ Ωε≥ε≡√⌡ ≡Φ±≤■≥ φστα∩εδφσφφ√σ ∞φεπε≤πεδⁿφΦΩΦ, α ΣΓα - τα∩εδφσφφ√σ. ╧σ≡Γ√Θ ∞σ≥εΣ ≡Φ±≤σ≥ φστα∩εδφσφφ√Θ ∞φεπε≤πεδⁿφΦΩ, ταΣαφφ√Θ ∞α±±ΦΓα∞Φ Ωεε≡ΣΦφα≥ ∩ε ε± ∞ X Φ Y: public abstract void drawPolygon( int xPoints[], int yPoints[], int nPoints); ╫σ≡στ ∩α≡α∞σ≥≡√ xPoints Φ yPoints ∩σ≡σΣα■≥± , ±εε≥Γσ≥±≥Γσφφε, ±±√δΩΦ φα ∞α±±ΦΓ√ Ωεε≡ΣΦφα≥ ∩ε εΦ± X Φ Y. ╧α≡α∞σ≥≡ nPoints ταΣασ≥ ΩεδΦ≈σ±≥Γε ≥ε≈σΩ Γ ∞α±±ΦΓα⌡. ═α ≡Φ±. 6 ∩εΩαταφ ∞φεπε≤πεδⁿφΦΩ, φα≡Φ±εΓαφφ√Θ ∞σ≥εΣε∞ drawPolygon. ╨Φ±. 6. ╠φεπε≤πεδⁿφΦΩ, φα≡Φ±εΓαφφ√Θ ∞σ≥εΣε∞ drawPolygon ┬ ²≥ε∞ ∞φεπε≤πεδⁿφΦΩσ °σ±≥ⁿ Γσ≡°Φφ ± Ωεε≡ΣΦφα≥α∞Φ ε≥ (x0, y0) Σε (x5, y5), ∩≡Φ≈σ∞ Σδ ≥επε ≈≥εß√ εφ ±≥αδ τα∞Ωφ≤≥√∞, Ωεε≡ΣΦφα≥√ ∩σ≡ΓεΘ Φ ∩ε±δσΣφσΘ Γσ≡°Φφ√ ±εΓ∩αΣα■≥. ┬≥ε≡εΘ ∞σ≥εΣ ≥αΩµσ ≡Φ±≤σ≥ φστα∩εδφσφφ√Θ ∞φεπε≤πεδⁿφΦΩ, εΣφαΩε Γ Ωα≈σ±≥Γσ ∩α≡α∞σ≥≡α ∞σ≥εΣ≤ ∩σ≡σΣασ≥± ±±√δΩα φα εß·σΩ≥ Polygon: public void drawPolygon(Polygon p); ╩δα±± Polygon Σε±≥α≥ε≈φε ∩≡ε±≥. ╧≡ΦΓσΣσ∞ ε∩Φ±αφΦσ σπε ∩εδσΘ, Ωεφ±≥≡≤Ω≥ε≡εΓ Φ ∞σ≥εΣεΓ: ╧εδ Ωδα±±α
╩εδΦ≈σ±≥Γε Γσ≡°Φφ public int npoints;
╠α±±ΦΓ Ωεε≡ΣΦφα≥ ∩ε ε±Φ X public int xpoints[];
╠α±±ΦΓ Ωεε≡ΣΦφα≥ ∩ε ε±Φ Y public int ypoints[] ╩εφ±≥≡≤Ω≥ε≡√public Polygon (); public Polygon(int xpoints[], int ypoints[], int npoints); ╠σ≥εΣ√
─εßαΓδσφΦσ Γσ≡°Φφ√ public void addPoint(int x, int y);
╧εδ≤≈σφΦσ Ωεε≡ΣΦφα≥ ε⌡Γα≥√Γα■∙σπε ∩≡ ∞ε≤πεδⁿφΦΩα public Rectangle getBoundingBox();
╧≡εΓσ≡Ωα, φα⌡εΣΦ≥± δΦ ≥ε≈Ωα Γφ≤≥≡Φ ∞φεπε≤πεδⁿφΦΩα public boolean inside(int x, int y); ═Φµσ ∞√ ∩εΩαταδΦ ⌠≡απ∞σφ≥ ΩεΣα, Γ Ωε≥ε≡ε∞ ±ετΣασ≥± ∞φεπε≤πεδⁿφΦΩ, α τα≥σ∞ Γ φσπε ΣεßαΓδ σ≥± φσ±ΩεδⁿΩε ≥ε≈σΩ. ╠φεπε≤πεδⁿφΦΩ ≡Φ±≤σ≥± ∞σ≥εΣε∞ drawPolygon: Polygon p = new Polygon(); p.addPoint(270, 239); p.addPoint(350, 230); p.addPoint(360, 180); p.addPoint(390, 160); p.addPoint(340, 130); p.addPoint(270, 239); g.drawPolygon(p); ┼±δΦ Γα∞ φ≤µφε φα≡Φ±εΓα≥ⁿ τα∩εδφσφφ√Θ ∞φεπε≤πεδⁿφΦΩ (≡Φ±. 7), ≥ε Σδ ²≥επε Γ√ ∞εµσ≥σ Γε±∩εδⁿτεΓα≥ⁿ± ∞σ≥εΣα∞Φ, ∩≡ΦΓσΣσφφ√∞Φ φΦµσ: public abstract void fillPolygon( int xPoints[], int yPoints[], int nPoints); public void fillPolygon(Polygon p); ╧σ≡Γ√Θ Φτ ²≥Φ⌡ ∞σ≥εΣεΓ ≡Φ±≤σ≥ ∞φεπε≤πεδⁿφΦΩ, Ωεε≡ΣΦφα≥√ Γσ≡°Φφ Ωε≥ε≡επε ταΣαφ√ Γ ∞α±±ΦΓα⌡, Γ≥ε≡εΘ - ∩εδ≤≈α εß·σΩ≥ Ωδα±±α Polygon Γ Ωα≈σ±≥Γσ ∩α≡α∞σ≥≡α. ╨Φ±. 7. ╠φεπε≤πεδⁿφΦΩ, φα≡Φ±εΓαφφ√Θ ∞σ≥εΣε∞ fillPolygon ╬Γαδ√ Φ Ω≡≤πΦ─δ ≡Φ±εΓαφΦ εΩ≡≤µφε±≥σΘ Φ εΓαδεΓ Γ√ ∞εµσ≥σ Γε±∩εδⁿτεΓα≥ⁿ± ∞σ≥εΣε∞ drawOval: public abstract void drawOval( int x, int y, int width, int height); ╧α≡α∞σ≥≡√ ²≥επε ∞σ≥εΣ√ ταΣα■≥ Ωεε≡ΣΦφα≥√ Φ ≡ατ∞σ≡√ ∩≡ ∞ε≤πεδⁿφΦΩα, Γ Ωε≥ε≡√Θ Γ∩Φ±√Γασ≥± ≡Φ±≤σ∞√Θ εΓαδ (≡Φ±. 8). ╨Φ±. 8. ╨Φ±εΓαφΦσ εΓαδα ╠σ≥εΣ fillOval ∩≡σΣφατφα≈σφ Σδ ≡Φ±εΓαφΦ τα∩εδφσφφεπε εΓαδα (≡Φ±. 9). ═ατφα≈σφΦσ σπε ∩α≡α∞σ≥≡εΓ αφαδεπΦ≈φε φατφα≈σφΦ■ ∩α≡α∞σ≥≡εΓ ∞σ≥εΣα drawOval: public abstract void fillOval( int x, int y, int width, int height); ╨Φ±. 9. ╨Φ±εΓαφΦσ τα∩εδφσφφεπε εΓαδα ╤σπ∞σφ≥√╠σ≥εΣ drawArc ∩≡σΣφατφα≈σφ Σδ ≡Φ±εΓαφΦ φστα∩εδφσφφεπε ±σπ∞σφ≥α (≡Φ±. 10). ╧≡ε≥ε≥Φ∩ ²≥επε ∞σ≥εΣα ∩≡ΦΓσΣσφ φΦµσ: public abstract void drawArc( int x, int y, int width, int height, int startAngle, int arcAngle); ╨Φ±. 10. ╨Φ±εΓαφΦσ φστα∩εδφσφφεπε ±σπ∞σφ≥α ╧α≡α∞σ≥≡√ x, y, width Φ height ταΣα■≥ Ωεε≡ΣΦφα≥√ ∩≡ ∞ε≤πεδⁿφΦΩα, Γ Ωε≥ε≡√Θ Γ∩Φ±αφ ±σπ∞σφ≥. ╧α≡α∞σ≥≡√ startAngle Φ arcAngle ταΣα■≥± Γ π≡αΣ≤±α⌡. ╬φΦ ε∩≡σΣσδ ■≥, ±εε≥Γσ≥±≥Γσφφε, φα≈αδⁿφ√Θ ≤πεδ Φ ≤πεδ ≡ατΓε≡ε≥α ±σπ∞σφ≥α. ─δ ≥επε ≈≥εß√ φα≡Φ±εΓα≥ⁿ τα∩εδφσφφ√Θ ±σπ∞σφ≥, Γ√ ∞εµσ≥σ Γε±∩εδⁿτεΓα≥ⁿ± ∞σ≥εΣε∞ fillArc: public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle); ╟αΣαφΦσ εßδα±≥Φ επ≡αφΦ≈σφΦ┼±δΦ Σδ εΩφα α∩δσ≥α ταΣα≥ⁿ εßδα±≥ⁿ επ≡αφΦ≈σφΦ , ≥ε ≡Φ±εΓαφΦσ ß≤Σσ≥ Γετ∞εµφε ≥εδⁿΩε Γ ∩≡σΣσδα⌡ ²≥εΘ εßδα±≥Φ. ╬ßδα±≥ⁿ επ≡αφΦ≈σφΦ ταΣασ≥± ∞σ≥εΣε∞ clipRect, ∩≡ε≥ε≥Φ∩ Ωε≥ε≡επε ∞√ ∩≡ΦΓσδΦ φΦµσ: public abstract void clipRect( int x, int y, int width, int height); ╧α≡α∞σ≥≡√ x, y, width Φ height ταΣα■≥ Ωεε≡ΣΦφα≥√ ∩≡ ∞ε≤πεδⁿφεΘ εßδα±≥Φ επ≡αφΦ≈σφΦ . ╩ε∩Φ≡εΓαφΦσ ±εΣσ≡µΦ∞επε ∩≡ ∞ε≤πεδⁿφεΘ εßδα±≥Φ╠σ≥εΣ copyArea ∩ετΓεδ σ≥ ±Ωε∩Φ≡εΓα≥ⁿ ±εΣσ≡µΦ∞εσ δ■ßεΘ ∩≡ ∞ε≤πεδⁿφεΘ εßδα±≥Φ εΩφα α∩δσ≥α: public abstract void copyArea( int x, int y, int width, int height, int dx, int dy); ╧α≡α∞σ≥≡√ x, y, width Φ height ταΣα■≥ Ωεε≡ΣΦφα≥√ Ωε∩Φ≡≤σ∞εΘ ∩≡ ∞ε≤πεδⁿφεΘ εßδα±≥Φ. ╬ßδα±≥ⁿ Ωε∩Φ≡≤σ≥± Γ Σ≡≤π≤■ ∩≡ ∞ε≤πεδⁿφ≤■ εßδα±≥ⁿ ≥αΩεπε µσ ≡ατ∞σ≡α, ∩≡Φ≈σ∞ ∩α≡α∞σ≥≡√ dx Φ dy ε∩≡σΣσδ ■≥ Ωεε≡ΣΦφα≥√ ∩ε±δσΣφσΘ. |